#include<bits/stdc++.h>
using namespace std;
int d[100005],v[100005],a[100005],p[100005];
vector<int> add[100005],era[100005];
using ll=long long;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,m,l,V;
        cin>>n>>m>>l>>V;
        for(int i=0;i<n;i++)cin>>d[i]>>v[i]>>a[i];
        for(int i=0;i<m;i++)cin>>p[i],add[i].clear(),era[i].clear();
        int ans1=0,ans2=m;
        for(int i=0;i<n;i++){
            if(a[i]==0){
                if(d[i]>p[m-1]||v[i]<=V)continue;
                add[lower_bound(p,p+m,d[i])-p].push_back(i);
                era[m-1].push_back(i);
            }
            else if(a[i]>0){
                ll tmp=max<ll>(d[i],d[i]+((ll)V*V-(ll)v[i]*v[i])/(2*a[i]));
                if(tmp>=p[m-1])continue;
                add[upper_bound(p,p+m,tmp)-p].push_back(i);
                era[m-1].push_back(i);
            }
            else {
                if(v[i]<=V)continue;
                int x=lower_bound(p,p+m,d[i])-p,y=upper_bound(p,p+m,d[i]+((ll)V*V-(ll)v[i]*v[i]+1)/(2*a[i]))-p-1;
                if(x>y)continue;
                add[x].push_back(i);
                era[y].push_back(i);
            }
             ++ans1;
        }
        set<int> s;
        for(int i=0;i<m;i++){
            for(int j:add[i])s.insert(j);
            for(int j:era[i])if(s.count(j)){
                s.clear();
                ans2--;break;
            }
        }
        cout<<ans1<<' '<<ans2<<'\n';
    }

}
